package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.tradewar.*;
import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.pb.tradewar.TradeWarProto;

import java.util.List;

public class CrossTradeWarPb {
    public static CrossTradeWarProto.CrossTradeWarBattleTempMsg.Builder parseCrossTradeWarBattleTempMsg(CrossUserTradeWarBattle crossUserTradeWarBattle, long score){
        if(null == crossUserTradeWarBattle){
            return null;
        }
        CrossTradeWarProto.CrossTradeWarBattleTempMsg.Builder msg = CrossTradeWarProto.CrossTradeWarBattleTempMsg.newBuilder();
        msg.setActivityId(crossUserTradeWarBattle.getActivityId());
        msg.addAllMyPatronsIdList(crossUserTradeWarBattle.getPatronsList());
        msg.setBuyBuffTimes(crossUserTradeWarBattle.getBuyBuffTimes());
        msg.setMyScore(score);
        msg.setEnemyUserId(crossUserTradeWarBattle.getEnemyUserId());
        PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(crossUserTradeWarBattle.getEnemyBaseInfo());
        msg.setEnemyBaseData(baseMsg);
        msg.setEnemyPatronsCount(crossUserTradeWarBattle.getEnemyPatronsCount());
        msg.setEnemyScore(crossUserTradeWarBattle.getEnemyScore());
        msg.setFastTeamNum(crossUserTradeWarBattle.getFastTeamNum());
        return msg;
    }

    public static TradeWarProto.TradeWarPatronsDataTempMsg.Builder parseTradeWarPatronsDataTempMsg(UserTradeWarPatronsData userTradeWarPatronsData){
        if(null == userTradeWarPatronsData){
            return null;
        }
        TradeWarProto.TradeWarPatronsDataTempMsg.Builder msg = TradeWarProto.TradeWarPatronsDataTempMsg.newBuilder();
        msg.setPatronsId(userTradeWarPatronsData.getPatronsId());
        msg.setBattleTimes(userTradeWarPatronsData.getCrossBattleTimes());
        msg.setBuyBattleTimes(userTradeWarPatronsData.getCrossBuyBattleTimes());
        msg.setRandomBattleTimes(userTradeWarPatronsData.getCrossRandomBattleTimes());
        msg.setRandomBattleRestoreTimes(userTradeWarPatronsData.getCrossRandomBattleRestoreTimes());
        msg.setRestoreRandomBattleTime(userTradeWarPatronsData.getCrossRestoreRandomBattleTime());

        return msg;
    }

    public static TradeWarProto.TradeWarPatronsDataListMsg.Builder parseTradeWarPatronsDataListMsg(List<UserTradeWarPatronsData> userTradeWarPatronsDataList){
        TradeWarProto.TradeWarPatronsDataListMsg.Builder listMsg = TradeWarProto.TradeWarPatronsDataListMsg.newBuilder();
        if(null != userTradeWarPatronsDataList){
            for(UserTradeWarPatronsData userTradeWarPatronsData : userTradeWarPatronsDataList){
                TradeWarProto.TradeWarPatronsDataTempMsg.Builder msg = parseTradeWarPatronsDataTempMsg(userTradeWarPatronsData);
                if(null != msg){
                    listMsg.addPatronsDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static CrossTradeWarNotice parseCrossTradeWarNotice(CrossTradeWarProto.CrossTradeWarNoticeTempMsg msg) {
        if(null == msg){
            return null;
        }
        CrossTradeWarNotice data = new CrossTradeWarNotice();
        data.setActivityId(msg.getActivityId());
        data.setUserId(msg.getUserId());
        data.setEnemyUserId(msg.getEnemyUserId());
        data.setBattleType(msg.getBattleType());
        data.setKillPatronsCount(msg.getKillPatronsCount());
        data.setAllKill(msg.getIsAllKill());
        data.setNoticeTime(msg.getNoticeTime());
        UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(msg.getPlayerBaseData());
        data.setUserBaseInfo(userBaseInfo);
        UserBaseInfo enemyBaseInfo = PlayerBasePb.parseToUserBaseInfo(msg.getEnemyBaseData());
        data.setEnemyBaseInfo(enemyBaseInfo);
        return data;
    }

    public static CrossTradeWarProto.CrossTradeWarNoticeTempMsg.Builder parseCrossTradeWarNoticeTempMsg(CrossTradeWarNotice notice) {
        if(null == notice){
            return null;
        }
        CrossTradeWarProto.CrossTradeWarNoticeTempMsg.Builder msg = CrossTradeWarProto.CrossTradeWarNoticeTempMsg.newBuilder();
        msg.setActivityId(notice.getActivityId());
        msg.setUserId(notice.getUserId());
        PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(notice.getUserBaseInfo());
        msg.setPlayerBaseData(baseMsg);
        msg.setKillPatronsCount(notice.getKillPatronsCount());
        msg.setNoticeTime(notice.getNoticeTime());
        baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(notice.getEnemyBaseInfo());
        msg.setEnemyBaseData(baseMsg);
        msg.setBattleType(notice.getBattleType());
        msg.setIsAllKill(notice.isAllKill());
        msg.setEnemyUserId(notice.getEnemyUserId());
        msg.setTotalChallengeTimes(notice.getTotalChallengeTimes());
        msg.setTotalKillPatronsCount(notice.getTotalKillPatronsCount());
        return msg;
    }

    public static CrossTradeWarProto.CrossTradeWarNoticeListMsg.Builder parseCrossTradeWarNoticeListMsg(List<CrossTradeWarNotice> noticeList) {
        CrossTradeWarProto.CrossTradeWarNoticeListMsg.Builder listMsg = CrossTradeWarProto.CrossTradeWarNoticeListMsg.newBuilder();
        if(null != noticeList) {
            for (CrossTradeWarNotice notice : noticeList) {
                CrossTradeWarProto.CrossTradeWarNoticeTempMsg.Builder msg = parseCrossTradeWarNoticeTempMsg(notice);
                if (null != msg) {
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static CrossTradeWarProto.CrossTradeWarSimpleNoticeTempMsg.Builder parseCrossTradeWarSimpleNoticeTempMsg(CrossTradeWarSimpleNotice data){
        if(null == data){
            return null;
        }
        CrossTradeWarProto.CrossTradeWarSimpleNoticeTempMsg.Builder msg = CrossTradeWarProto.CrossTradeWarSimpleNoticeTempMsg.newBuilder();
        msg.setActivityId(data.getActivityId());
        msg.setUserId(data.getUserId());
        msg.setServerId(data.getServerId());
        msg.setEnemyUserId(data.getEnemyUserId());
        msg.setEnemyServerId(data.getEnemyServerId());
        msg.setKillPatronsCount(data.getKillPatronsCount());
        msg.setNoticeTime(data.getNoticeTime());
        return msg;
    }

    public static CrossTradeWarProto.CrossTradeWarSimpleNoticeListMsg.Builder parseCrossTradeWarSimpleNoticeListMsg(List<CrossTradeWarSimpleNotice> dataList){
        CrossTradeWarProto.CrossTradeWarSimpleNoticeListMsg.Builder listMsg = CrossTradeWarProto.CrossTradeWarSimpleNoticeListMsg.newBuilder();
        if(null != dataList){
            for(CrossTradeWarSimpleNotice data : dataList){
                CrossTradeWarProto.CrossTradeWarSimpleNoticeTempMsg.Builder msg = parseCrossTradeWarSimpleNoticeTempMsg(data);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static CrossTradeWarProto.CrossTradeWarWantedRecordTempMsg.Builder parseCrossTradeWarWantedRecordTempMsg(CrossTradeWarWantedRecord data){
        if(null == data){
            return null;
        }
        CrossTradeWarProto.CrossTradeWarWantedRecordTempMsg.Builder msg = CrossTradeWarProto.CrossTradeWarWantedRecordTempMsg.newBuilder();
        msg.setActivityId(data.getActivityId());
        msg.setWantedUserId(data.getWantedUserId());
        msg.setWantedServerId(data.getWantedServerId());
        msg.setWantedTime(data.getWantedTime());
        return msg;
    }

    public static CrossTradeWarProto.CrossTradeWarWantedRecordListMsg.Builder parseCrossTradeWarWantedRecordListMsg(List<CrossTradeWarWantedRecord> dataList){
        CrossTradeWarProto.CrossTradeWarWantedRecordListMsg.Builder listMsg = CrossTradeWarProto.CrossTradeWarWantedRecordListMsg.newBuilder();
        if(null != dataList){
            for(CrossTradeWarWantedRecord data : dataList){
                CrossTradeWarProto.CrossTradeWarWantedRecordTempMsg.Builder msg = parseCrossTradeWarWantedRecordTempMsg(data);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }
}
